package hbt;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class HibernateUtil {
	
		private static final SessionFactory sessionFactory;
		static
		{
			try
			{
				AnnotationConfiguration config = new AnnotationConfiguration();

				/* NOTA:
				 * Para un mejor mantenimiento ubicar las clases por orden alfabetico
				 */
				
				config.addAnnotatedClass(entities.AdministracionEntity.class);
				config.addAnnotatedClass(entities.AperturaMesaEntity.class);
				config.addAnnotatedClass(entities.AreaEntity.class);
				config.addAnnotatedClass(entities.CartaEntity.class);
				config.addAnnotatedClass(entities.CajaEntity.class);
				config.addAnnotatedClass(entities.CartaEntity.class);
				config.addAnnotatedClass(entities.ComandaEntity.class);
				config.addAnnotatedClass(entities.DepositoEntity.class);
				config.addAnnotatedClass(entities.FacturaEntity.class);
				config.addAnnotatedClass(entities.IngredienteEntity.class);
				config.addAnnotatedClass(entities.MesaEntity.class);
				config.addAnnotatedClass(entities.MovimientoEntity.class);
				config.addAnnotatedClass(entities.MozoEntity.class);
				config.addAnnotatedClass(entities.OrdenCompraEntity.class);
				config.addAnnotatedClass(entities.ProveedorEntity.class);
				config.addAnnotatedClass(entities.PlanProduccionEntity.class);
				config.addAnnotatedClass(entities.PersonalEntity.class);
				config.addAnnotatedClass(entities.PedidoEntity.class);
				config.addAnnotatedClass(entities.PerfilEntity.class);
				config.addAnnotatedClass(entities.PlatoEntity.class);
				config.addAnnotatedClass(entities.ProductoEntity.class);
				config.addAnnotatedClass(entities.RemitoEntity.class);
				config.addAnnotatedClass(entities.SolicitudInsumoEntity.class);
				config.addAnnotatedClass(entities.SalonEntity.class);
				config.addAnnotatedClass(entities.SectorEntity.class);
				config.addAnnotatedClass(entities.SalonEntity.class);
				config.addAnnotatedClass(entities.SucursalEntity.class);
				config.addAnnotatedClass(entities.TipoProductoEntity.class);
			
				config.addAnnotatedClass(entities.ItemCartaEntity.class);
				config.addAnnotatedClass(entities.ItemDepositoEntity.class);
				config.addAnnotatedClass(entities.ItemOrdenCompraEntity.class);
				config.addAnnotatedClass(entities.ItemPlanProduccionEntity.class);
				config.addAnnotatedClass(entities.ItemRemitoEntity.class);
				config.addAnnotatedClass(entities.ItemSolicitudInsumoEntity.class);
				
				sessionFactory = config.buildSessionFactory();

			}
			catch (Throwable ex)
			{
				System.err.println("Initial SessionFactory creation failed." + ex);
				throw new ExceptionInInitializerError(ex);
			}
		}

		public static Session getSession()throws HibernateException {
			return sessionFactory.openSession();
		}

		public static SessionFactory getSessionFactory()
		{
			return sessionFactory;
		}
}
